package com.acwing.partition18;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author `RKC`
 * @date 2022/2/2 19:06
 */
public class AC1776牛的基因组学 {

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        int n = Integer.parseInt(ss[0]), m = Integer.parseInt(ss[1]);
        String[] s1 = new String[n], s2 = new String[n], ss1 = new String[m], ss2 = new String[m];
        for (int i = 0; i < n; i++) s1[i] = reader.readLine();
        for (int i = 0; i < n; i++) s2[i] = reader.readLine();
        Map<Integer, List<Integer>> map1 = new HashMap<>(m), map2 = new HashMap<>(m);
        for (int i = 0; i < m; i++) {
            List<Integer> item = new ArrayList<>(n);
            map1.put(i, item);
            for (String s : s1) item.add((int) s.charAt(i));
        }
        for (int i = 0; i < m; i++) {
            List<Integer> item = new ArrayList<>(n);
            map2.put(i, item);
            for (String s : s2) item.add((int) s.charAt(i));
        }
        //计算有多少列交集是null
        int ans = 0;
        for (int i = 0; i < m; i++) {
            List<Integer> item1 = map1.get(i), item2 = map2.get(i);
            item1.retainAll(item2);
            if (item1.size() == 0) ans++;
        }
        writer.write(ans + "\n");
        writer.flush();
    }
}
